package edu.sctu.xiangkun.day201506.day20150606;

import java.util.Calendar;

/**
 * Created by lenovo on 2015/6/6.
 */
public class DateAndTime {

    Calendar calendar = Calendar.getInstance();

    public void getDateAndTime(){
        int year = calendar.get(calendar.YEAR);

        int month = calendar.get(calendar.MONTH)+1;

        int day = calendar.get(calendar.DAY_OF_MONTH);

        int hour = calendar.get(calendar.HOUR_OF_DAY);

        int minute = calendar.get(calendar.MINUTE);

        int second = calendar.get(calendar.SECOND);

        int week = calendar.get(calendar.DAY_OF_WEEK)-1;

        System.out.println("现在时间："+year+"-"+month+"-"+day+"\t"+hour+":"+minute+":"+second+"\t星期"+week);

    }
    public void setDateAndTime(){
        System.out.println("******请注意搭乘地铁时间******");

        calendar.set(calendar.HOUR_OF_DAY,06);
        calendar.set(calendar.MINUTE,00);
        calendar.set(calendar.SECOND,00);
        int hour = calendar.get(calendar.HOUR_OF_DAY);
        int minute = calendar.get(calendar.MINUTE);
        int second = calendar.get(calendar.SECOND);
        System.out.println("地铁发车时间："+hour+":"+minute+":"+second);

        calendar.set(calendar.HOUR_OF_DAY,23);
        calendar.set(calendar.MINUTE,00);
        calendar.set(calendar.SECOND,00);
        int hour1 = calendar.get(calendar.HOUR_OF_DAY);
        int minute1 = calendar.get(calendar.MINUTE);
        int second1 = calendar.get(calendar.SECOND);
        System.out.println("地铁收车时间："+hour1+":"+minute1+":"+second1);
    }
}
